package sjtu.sonnet.LDAPModule.service.impl;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;

import sjtu.sonnet.LDAPModule.service.LDAPBean;

public class LDAPBeanImpl implements LDAPBean {
	public LDAPBeanImpl() {
		
	}

	public void setCtx(DirContext ctx) {
		this.ctx = ctx;
	}

	public DirContext getCtx() {
		return ctx;
	}

	public void setEnv(Hashtable<Object, Object> env) {
		this.env = env;
	}

	public Hashtable<Object, Object> getEnv() {
		return env;
	}

	public void setBaseDN(String baseDN) {
		this.baseDN = baseDN;
	}

	public String getBaseDN() {
		return baseDN;
	}

	public void setProviderUrl(String providerUrl) {
		this.providerUrl = providerUrl;
	}

	public String getProviderUrl() {
		return providerUrl;
	}

	public void setContextFactory(String contextFactory) {
		this.contextFactory = contextFactory;
	}

	public String getContextFactory() {
		return contextFactory;
	}

	public void setSecurityAuthentication(String securityAuthentication) {
		this.securityAuthentication = securityAuthentication;
	}

	public String getSecurityAuthentication() {
		return securityAuthentication;
	}

	public void setSecurityPrincipal(String securityPrincipal) {
		this.securityPrincipal = securityPrincipal;
	}

	public String getSecurityPrincipal() {
		return securityPrincipal;
	}

	public void setSecurityCredential(String securityCredential) {
		this.securityCredential = securityCredential;
	}

	public String getSecurityCredential() {
		return securityCredential;
	}

	public void LDAPInit() {
		env = new Hashtable<Object, Object>();
		env.put(Context.INITIAL_CONTEXT_FACTORY, this.contextFactory);
		env.put(Context.PROVIDER_URL, this.providerUrl);
		env.put(Context.SECURITY_AUTHENTICATION, this.securityAuthentication);
		env.put(Context.SECURITY_PRINCIPAL, this.securityPrincipal);
		env.put(Context.SECURITY_CREDENTIALS, this.securityCredential);
		try {
			ctx = new InitialDirContext(env);
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}

	private DirContext ctx = null;
	private Hashtable<Object, Object> env = null;
	private String baseDN = "ou=prp3,ou=system";
	private String providerUrl = null;
	private String contextFactory = null;
	private String securityAuthentication = null;
	private String securityPrincipal = null;
	private String securityCredential = null;

}
